<?
class Trash extends Controller{
    function __construct(){
        $this->load->language('admin/en');
        $this->load->model('admin_function');
        $this->admin_function->valid_seeion_admin('signin',true);
    }
    function index(){
        $this->all();
    }
    
    function all(){        
    $data['template']='trash/all';
    $array['base_url']=base_url().ADMIN_FOLDER.'/'.$this->uri->segment(2).'/all';
    $array['table']='trash';
    $data['result']=analize_pagination($array);
    $this->load->view('template',$data);
    }
    
 
    
    function delete_item(){
        $path=array(
        ''  =>AVATAR_IMAGES_PATH,
        'member'  =>AVATAR_IMAGES_PATH,
        'china'   =>CHINA_IMAGES_PATH,
        'slider'  =>SLIDER_IMAGES_PATH,
        'product' =>PRODUCT_IMAGES_PATH,
        'order'   =>PRODUCT_IMAGES_PATH
        );
        $table=mysql_real_escape_string($this->uri->segment(4));
        $id=mysql_real_escape_string($this->uri->segment(5));
        $trash_id=mysql_real_escape_string($this->uri->segment(6));
        $sql=$this->db->get_where($table,array('ID'=>$id));
        if($sql->num_rows()){
            $row=$sql->row();
            $this->db->delete($table,array('ID'=>$id));
            $this->db->delete('trash',array('ID'=>$trash_id));
            if($table == 'bill'){
                $this->db->delete('bill_related',array('bill_id'=>$id));
            }
            $row=$sql->row();
            if(!empty($row->file)){
             @unlink($path[$table].$row->file);   
            }
//            $this->admin_function->creat_report($this->session->userdata('ADMIN_NAME'),'delete',2,$row->title);
            $data['message']=$this->lang->line('delete_success');
            $data['template']='message/success_';
        }else{
            $data['message']=$this->lang->line('worng_url');
            $data['template']='message/error_';
        }
        $this->load->view('template',$data);
            
        }
    function return_item(){
        $table=mysql_real_escape_string($this->uri->segment(4));
        $id=mysql_real_escape_string($this->uri->segment(5));
        $trash_id=mysql_real_escape_string($this->uri->segment(6));
        $sql=$this->db->get_where($table,array('ID'=>$id));
        if($sql->num_rows()){
            $row=$sql->row();
            $this->db->update($table,array('trash'=>'NO'),array('ID'=>$id));
            $this->db->delete('trash',array('ID'=>$trash_id));
            
            if($table == 'bill'){
                $this->db->update('bill_related',array('trash'=>'NO'),array('bill_id'=>$id));
            }
            //$row=$sql->row();
//            $this->admin_function->creat_report($this->session->userdata('ADMIN_NAME'),'delete',2,$row->title);
            $data['message']=$this->lang->line('edit_success');
            $data['template']='message/success_';
        }else{
            $data['message']=$this->lang->line('worng_url');
            $data['template']='message/error_';
        }
        $this->load->view('template',$data);
            
        }
        
        function action_all(){
        $do=$this->input->post('do_all');
        if(empty($_POST['ch_all_id'])){
         $ch_all_id=array();   
        }else{
        $ch_all_id=$_POST['ch_all_id'];
        }
        $ip=$this->input->post('ip');
        if(count($ch_all_id) > 0){
        if($do == 'delete'){
            foreach($ch_all_id as $key => $id){
            $id=explode('-',$id);
            $this->db->delete($id[0],array('ID'=>$id[1]));

/*if($id[0] == 'member'){
$this->db->delete->('address_book',array('user_add'=>$id[1]));
$this->db->delete->('order',array('user_add'=>$id[1]));
$this->db->delete->('coupon',array('user_id'=>$id[1]));
}*/
  


            $this->db->delete('trash',array('table'=>$id[0],'table_id'=>$id[1]));
            //$this->admin_function->move_to_trash('pages',array('ID'=>$id));
            $data['message']=$this->lang->line('delete_success');
            $data['template']='message/success_';
            }
           
        }elseif($do == 'undelete'){
            foreach($ch_all_id as $key => $id){
            $id=explode('-',$id);
            $this->db->update($id[0],array('trash'=>'NO'),array('ID'=>$id[1]));
            $this->db->delete('trash',array('table'=>$id[0],'table_id'=>$id[1]));
            $data['message']=$this->lang->line('edit_success');
            $data['template']='message/success_';
            }

        }elseif($do == 'unactive'){
            foreach($ch_all_id as $key => $id){
            $this->db->update('pages',array('active'=>'NO'),array('ID'=>$id));
            $data['message']=$this->lang->line('edit_success');
            $data['template']='message/success_';
            }

        }
      }else{
            $data['message']=$this->lang->line('action_all_error');
            $data['template']='message/error_';          
      }
    $this->load->view('template',$data);   
        }
        

    }

?>